package com.ty.enums;

import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Optional;

public enum PoStatus {

    NEW (1,"新建(待审核)"),
    APPROVE(2,"审核通过"),
    DISTRIBUTION(3,"配货中"),
    FINISH(4,"已入库"),
    FINISHOUT(5,"已出库"),
    REJECT(10,"驳回"),
    CANCEL(20,"报废");

    @Getter @Setter
    private int code;
    @Getter @Setter
    private String message;

    PoStatus(int code, String message){
        this.code =code;
        this.message =message;
    }

    public static PoStatus getByCode(int code){
        PoStatus[] values = PoStatus.values();
        //jdk1.8 “新”特性 stream流
        //jdk1.8 “新”特性 Optional
        Optional<PoStatus> first = Arrays.stream(values).filter(item -> item.getCode() == code).findFirst();
        //        if( first.isPresent()){ //如果这个Optional容器里面有值，就返回 get() 返回容器里面的值
//            return first.get();
//        }
//        return null;

        return first.orElse(null);
    }
}
